﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpShare.Storage;
using SharpShare.Diagnostics;

namespace SharpShare.Afp.Protocol.Handlers {
    internal class AfpSetDirectoryParamsRequestHandler : IAfpRequestHandler {
        #region IAfpRequestHandler Members

        public byte CommandCode {
            get { return 29; }
        }

        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) {
            requestStream.ReadPadding();

            ushort volumeId = requestStream.ReadUInt16();
            uint directoryID = requestStream.ReadUInt32();
            AfpFileDirectoryBitmap bitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();
            IAfpVolume volume;
            IStorageContainer item = requestStream.ReadPathAndFind(session, volumeId, directoryID, out volume).DemandContainer();

            requestStream.ReadPadding();

            AfpResultCode result = item.SetStorageItemParameters(volume, bitmap, requestStream);

            Log.Add(session, EntryType.Debug, "Session '{0}' set parameters '{1}' on container '{2}'.", session, bitmap, item);

            return result;
        }

        #endregion
    }
}
